/**重置密码后提交
 */

$("#oldPsw").on("blur",function () {
	if(!$(this).val()){
		$("#oldPaw").html("*必填").show();
	}else{
		 $("#oldPaw").hide(); 
	}
});
//确认修改
$("#submit").click(function(){
	var newPsw = $("#newPsw").val(),oldPsw = $("#oldPsw").val(),againPsw = $("#againPsw").val();
    var param = {"newPassword": newPsw, "oldPassword":oldPsw};   
    $.ajax({
        type: "POST",
        url: "/web-adv/updatePassword",
        dataType: "json",
        data: param,
        success: function (json) { 
        	 if (json.status == -1) {
        		 if(!$("#oldPsw").val()){
        			 $("#oldPaw").hide(); 
        			 $("#oldPsw").attr("checkStatus","1");
        		 }else{
        			 $("#oldPaw").show();
        			 $("#oldPaw").text(json.error)
        		 }
             } else {
            	 var path=escape('selectedNav=0&navPos=4');
                 window.location.href = "/web-adv/advWeb/views/userCenter/accountSecurity/modifyPwdSuccess.html?"+path;
             }           	
         },
         error: function () {
         }
    }); 
});


$(function(){
	//获取会员名
	var model;
	$.ajax({
		url:'/web-adv/gainName',
		type:"POST",
		dataType:"json",
		success : function(data){
			$("#memberName").val(data.memberName);
		},
		error : function(){
			console.log("err");
		}
	})
	$("#error_oldPsw").hide();
	//密码格式验证
	function codepat(){
		var codeVal=$("#newPsw").val();
		var patCode=/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,16}$/;
		if(patCode.test(codeVal)){
			return true;
		}else{
			return false;
		}
	};
	function codepat2(){
		var codeVal=$("#newPsw").val();
		var patNone=/[\s]/;
		if(patNone.test(codeVal)){
			return true;
		}else{
			return false;
		}
	};
	$("#newPsw").on("blur",function(){
		var result=codepat();
		var result2=codepat2();
		if(!$("#newPsw").val()){
			$("#error_oldPsw").html("*必填").show();		
		}else if(result && !result2){
			$("#error_oldPsw").hide();
		}else{
			$("#error_oldPsw").html("*6-16位字母、数字和符号(除空格),至少含2种");		
		}
	});
	$("#againPsw").on("blur",function(){
		var passWordAgain=$("#againPsw").val();
		var passWord=$("#newPsw").val();
		if(!passWordAgain){
			$(".secondpass").html("*必填").show();	
		}else if(passWordAgain!=passWord){
			$(".secondpass").show();
			$(".secondpass").html("*请保证密码一致");
		}else{
			$(".secondpass").hide();
		}
	});
})
